//app.js
var util = require('utils/util.js');
App({
  onLaunch: function() {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  getUserInfo: function(cb) {
    var that = this
    if (this.globalData.systemInfo != null) {
      typeof cb == "function" && cb(this.globalData.systemInfo)
    } else {
      //调用登录接口
      wx.login({
        success: function() {
          wx.getUserInfo({
            success: function(res) {
              that.globalData.systemInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.systemInfo)
            }
          })
        }
      })
    }
  },
  getSystemInfo: function(cb) {
    var that = this
    if (that.globalData.userInfo) {
      typeof cb == "function" && cb(that.globalData.userInfo)
    } else {
      wx.getSystemInfo({
        success: function(res) {
          that.globalData.userInfo = res
          typeof cb == "function" && cb(that.globalData.userInfo)
        }
      })
    }
  },

  //第一种状态的底部  
  editTabBar: function () {
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    if (_pagePath.indexOf('/') != 0) {
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabBar;
    for (var i = 0; i < tabBar.list.length; i++) {
      tabBar.list[i].active = false;
      if (tabBar.list[i].pagePath == _pagePath) {
        tabBar.list[i].active = true;//根据页面地址设置当前页面状态    
      }
    }
    _curPage.setData({
      tabBar: tabBar
    });
  },
  //第二种状态的底部  
  editTabBar2: function () {
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    if (_pagePath.indexOf('/') != 0) {
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabBar2;
    for (var i = 0; i < tabBar.list.length; i++) {
      tabBar.list[i].active = false;
      if (tabBar.list[i].pagePath == _pagePath) {
        tabBar.list[i].active = true;//根据页面地址设置当前页面状态    
      }
    }
    _curPage.setData({
      tabBar: tabBar
    });
  },
  globalData: {
    userInfo: null,
    sk:null,
    isCheck:null,
    systemInfo:null,
    tabBar: {
      "color": "#aaa",
      "selectedColor": "#3F87F5",
      "backgroundColor": "#fff",
      "borderStyle": "#aaa",
      "list": [
        {
          "pagePath": "/pages/home/home",
          "text": "首页",
          "iconPath": "/images/home.png",
          "selectedIconPath": "/images/home_in.png",
          "selectedIconPath": "/images/home_in.png",
          "clas": "menu-item",
          "selectedColor": "#4665f9",
          active: true
        },
        {
          "pagePath": "/pages/aduting/aduting",
          "text": "审核",
          "iconPath": "/images/aduting.png",
          "selectedIconPath": "/images/aduting_in.png",
          "clas": "menu-item",
          active: false
        },
        {
          "pagePath": "/pages/select/select",
          "text": "查询",
          "iconPath": "/images/select.png",
          "selectedIconPath": "/images/select_in.png",
          "clas": "menu-item",
          active: false
        },
        {
          "pagePath": "/pages/my/my",
          "text": "我的",
          "iconPath": "/images/my.png",
          "selectedIconPath": "/images/my_in.png",
          "clas": "menu-item",
          active: false
        }
      ],
      "position": "bottom"
    },
    tabBar2: {
      "color": "#9E9E9E",
      "selectedColor": "#f00",
      "backgroundColor": "#fff",
      "borderStyle": "#ccc",
      "list": [
        {
          "pagePath": "/pages/roomPattern/roomPattern",
          "text": "房态图",
          "iconPath": "/images/homeimg_on.png",
          "selectedIconPath": "/images/homeimg.png",
          "clas": "menu-item2",
          "selectedColor": "#4665f9",
          active: true
        },
        {
          "pagePath": "/pages/zjPage/sharePage/sharePageList",
          "text": "分享",
          "iconPath": "/images/share_out.png",
          "selectedIconPath": "/images/share_on.png",
          "selectedColor": "#4665f9",
          "clas": "menu-item2",
          active: false
        },
        {
          "pagePath": "/pages/my/my",
          "text": "我的",
          "iconPath": "/images/my.png",
          "selectedIconPath": "/images/my_in.png",
          "selectedColor": "#4665f9",
          "clas": "menu-item2",
          active: false
        },
       
      ],
      "position": "bottom"
    }
  }  
})